package admin

import (
	"backend_api/internal/model/request"
	"backend_api/internal/service"
	"github.com/gin-gonic/gin"
	"net/http"
)

type WebsiteSettingController struct{}

func (c *WebsiteSettingController) GetSetting(ctx *gin.Context) {
	var service service.WebsiteSettingService
	setting, err := service.GetSetting()
	if err != nil {
		ctx.JSON(http.StatusOK, gin.H{
			"code": 404,
			"msg":  "获取设置失败",
		})
		return
	}
	ctx.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "OK",
		"data": setting,
	})
}

func (c *WebsiteSettingController) UpdateSetting(ctx *gin.Context) {
	var req request.WebsiteSettingUpdate
	if err := ctx.ShouldBindJSON(&req); err != nil {
		ctx.JSON(http.StatusOK, gin.H{
			"code": 404,
			"msg":  "参数错误",
		})
		return
	}

	var service service.WebsiteSettingService
	if err := service.UpdateSetting(&req); err != nil {
		ctx.JSON(http.StatusOK, gin.H{
			"code": 404,
			"msg":  "更新失败",
		})
		return
	}
	ctx.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "OK",
		"data": nil,
	})
}
